package com.itqf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.dto.SearchDto;
import com.itqf.mapper.BillMapper;
import com.itqf.pojo.Bill;
import com.itqf.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: springmvcgp8
 *
 * @author: 赵伟风
 * time: 2021/8/9 17:48
 * description:
 */
@Service
public class BillServiceImpl implements BillService {

    @Autowired
    private BillMapper billMapper;
    /**
     * 条件查询账单
     *
     * @param searchDto
     * @return
     */
    @Override
    public Map<String, Object> search(SearchDto searchDto) {

        //1.设置分页属性

        PageHelper.startPage(searchDto.getPage(), searchDto.getPageSize());

        //2.查询
        List<Bill> bills = billMapper.queryByDto(searchDto);

        //3.封装pageInfo

        PageInfo<Bill> pageInfo = new PageInfo<>(bills);

        //4.封装返回结果

        Map<String,Object> data = new HashMap<>();
        data.put("code", 200);
        data.put("msg", "");
        data.put("data", pageInfo.getList());

        return data;
    }

    @Override
    public Map<String, Object> remove(int id) {

        int rows = billMapper.delete(id);

        Map<String,Object> data = new HashMap<>();
        data.put("code", 500);
        if (rows > 0){
            data.put("code", 200);
        }
        data.put("msg", "");


        return data;
    }


}
